package main

import (
	"math/rand"
	"time"
)

const (
	stringList  = "qazwsxedcrfvtgbyhnujmikolQAZWSXEDCRFVTGBYHNMJUIKLOP"
	intList     = "1234567890"
	punctuation = `!@#$%^&*()_+|}{":?></.,';`
	StringInt   = stringList + intList
	stringPunc  = stringList + punctuation
	allThis     = stringList + intList + punctuation
)

func GenerateAll() []string {
	//initSeed()
	var passwdList = []string{}
	passLen := rand.Intn(20) + 10
	passwdList = append(passwdList, GeneratePasswdComplex(passLen))
	passwdList = append(passwdList, GeneratePasswdMiddle(passLen))
	a, b := GeneratePasswdSimple(passLen)
	passwdList = append(passwdList, a)
	passwdList = append(passwdList, b)
	return passwdList
}

// 生成一个当前纳秒时间的种子，确保唯一性
func initSeed() {
	seed := (time.Time{}.UnixNano())
	rand.Seed(seed)
}

// 复杂密码
func GeneratePasswdComplex(passLen int) string {
	var passwd = make([]byte, passLen)
	for i := range passwd {
		passwd[i] = allThis[rand.Intn(len(allThis))]
	}
	return string(passwd)
}

// 中难度密码
func GeneratePasswdMiddle(passLen int) string {
	var passwd = make([]byte, passLen)
	for i := range passwd {
		passwd[i] = stringPunc[rand.Intn(len(stringPunc))]
	}
	return string(passwd)
}

// 简单密码
func GeneratePasswdSimple(passLen int) (a, b string) {
	var passwdStr = make([]byte, passLen)
	var passwdStrInt = make([]byte, passLen)
	for i := range passwdStr {
		passwdStr[i] = stringList[rand.Intn(len(stringList))]
	}
	for i := range passwdStrInt {
		passwdStrInt[i] = StringInt[rand.Intn(len(StringInt))]
	}
	return string(passwdStr), string(passwdStrInt)
}
